<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加用户</title>
    <jsp:include page="includes/resources.jsp"/>
</head>
<body>
    <form action="/user/add" method="post">
        <h1>新增</h1>
        用户名:<input type="text" name="name"></br>
        性别:<input type="text" name="sex">
        创建时间:<input type="text" name="createTime">
        <input type="submit" value="提交"/>
    </form>
    <input type="button" onclick="testHit1();" value="user/add(JsonObject)"/>
    <input type="button" onclick="testHit2();" value="user/add(JsonString)"/>
    <input type="button" onclick="testHit3();" value="test/user(JsonObject)"/>
    <input type="button" onclick="testHit4();" value="test/user(JsonString)"/>
</body>


<script>
    function testHit1(){
        $.ajax({
            url: '/user/add',
            type: 'post',
            data: { name:"2323", sex:12 },
            dataType: "json",
            contentType: "application/json",
            async:true,
            success: function(data) {
                alert(data);
            }
        });
    }
    function testHit2(){
        $.ajax({
            url: '/user/add',
            type: 'post',
            data: { "name":"2323", "sex":"12" },
            dataType: "json",
            contentType: "application/json",
            async:true,
            success: function(data) {
                alert(data);
            }
        });
    }
    function testHit3(){
        $.ajax({
            url: '/test/user',
            type: 'post',
            data: { "name":"2323", "sex":"12" },
            dataType: "json",
            contentType: "application/json",
            async:true,
            success: function(data) {
                alert(data);
            }
        });
    }
    function testHit4(){
        $.ajax({
            url: '/test/user',
            type: 'post',
            data: '{ "name":"2323", "sex":"12", "createTime":"2018-01-01 22:11:11" }',
            dataType: "json",
            contentType: "application/json",
            async:true,
            success: function(data) {
                alert(data);
            }
        });
    }

    var data1 = { "name":"2323", "sex":"12" };  //标准json格式对象,无法接

    var data2 = { name:"2323", sex:12 };        //非标准json对象,无法接

    var data3 = { "name":"2323", "sex":12 };    //非标准json格式对象,无法接

    var data4 = '{ "name":"2323", "sex":"12" }';//标准json字符串,使用@RequestBody标注的对象接收

    var data5 = '{ "name":"2323", "sex":12 }';  //非标准json字符串,使用@RequestBody标注的对象接收

    var data6 = '{ name:"2323", sex:12 }';      //非标准json格式字符串,无法接收
</script>

</html>
